#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <pcap/pcap.h>
pcap_dumper_t *g_dump = NULL;
int main(int argc, char **argv)
{
	pcap_t *handle[4];
	struct pcap_file_header pcapfh;	
	struct pcap_pkthdr pkthdr;
	u_char *pktdata;
	char error[100];
	struct pcap_stat pcap_info;
	int pktnum = 0;
	int i = 0;
	for (i = 1; i <= argc-1; i++) {
	printf("filename is:%s\n", argv[i]);
	if((handle[i-1]=pcap_open_offline(argv[i] ,error))==NULL)  //打开文件
    	{
        	printf("%s\n",error);
        	return 0;
	}
	if (g_dump == NULL)
		g_dump = pcap_dump_open(handle[i-1], "tmp.pcap");
	while(1) {
		pktdata = pcap_next(handle[i-1], &pkthdr);
		if (pkthdr.len && pktdata == NULL)
			break;
	printf("caplen:%d\n, len:%d\n, time of sec:%ul\n, time of usec:%ul\n", pkthdr.caplen, pkthdr.len, pkthdr.ts.tv_sec, pkthdr.ts.tv_usec);
	printf("user data:%s\n", pktdata);
	pcap_dump((u_char*)g_dump, &pkthdr, pktdata);
	}
	}
	pcap_dump_flush(g_dump);
	pcap_dump_close(g_dump);
	return 0;
}
